﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;


namespace HTMLDecoder
{
    public class HTMLStream : Stream
    {
        private readonly FileStream _inStream;
        private FileStream _outStream;
        public HTMLStream(string initialFilePath)
        {
            _inStream = File.OpenRead(initialFilePath);
          
        }
        public override bool CanRead
        {
            get { return _inStream.CanRead; }
        }

        public override bool CanSeek
        {
            get { return _inStream.CanSeek; }
        }

        public override bool CanWrite
        {
            get { return _inStream.CanWrite; }
        }

        public override void Flush()
        {
            throw new Exception("This stream does not support writing.");
        }

        public override long Length
        {
            get { return _inStream.Length; }
        }

        public override long Position
        {
            get
            {
                return _inStream.Position;
            }
            set
            {
                throw new Exception("This stream does not support setting the Position property.");
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            int newSize=_inStream.Read(buffer, offset, count);
            return HtmlDecoder.DecodeEntity(buffer, 0, newSize);
             
            
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new Exception("This stream does not support seeking.");
        }

        public override void SetLength(long value)
        {
            throw new Exception("This stream does not support setting the Length.");
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            throw new Exception("This stream does not support writing.");
        }
        public override void Close()
        {
            _inStream.Close();
            base.Close();
        }
        protected override void Dispose(bool disposing)
        {
            _inStream.Dispose();
            base.Dispose(disposing);
        }
        
    }
}
